﻿using Demo.Domains.Entities.Sys;
using Demo.PetaPoco.Application.DbContexts;
using Demo.PetaPoco.Application.Dtos.Menu;
using Microsoft.Extensions.DependencyInjection;
using PetaPoco;
using PmSoft.Cache.Abstractions;
using PmSoft.Core;
using PmSoft.Data.PetaPoco.Repositories;

namespace Demo.PetaPoco.Application.Services.Menu;

[Inject(ServiceLifetime.Scoped)]
public class MenuRepository : CacheRepository<AppDbContext, SysMenu, int>
{
	public MenuRepository(AppDbContext dbContext, IApplicationContext applicationContext) : base(dbContext, applicationContext)
	{
	}


	public async Task<IEnumerable<SysMenu>> GetAllMenuAsync()
	{
		return await GetTopEntitiesWithCacheAsync(2000,
		   CachingExpirationType.RelativelyStable,
		   () => "AllMenu",
		   () =>
		   {
			   Sql sql = Sql.Builder;
			   return sql;
		   });
	}
}
